const { SuccessModel, ErrorModel } = require('../model/resModel')
const { loginCheck } = require('../controller/user')

const handleUserRouter = (req, res) => {
    const method = req.method // GET或POST
    if (method === 'POST' && req.path === '/api/user/login') {
        const { username, password } = req.body
        return loginCheck(username, password).then(data => {
            if (data.username) {
                return SuccessModel() // 查询出数据
            } else {
                return ErrorModel('登录失败') // 没有查询到数据
            }
        })
    }
}

module.exports = handleUserRouter
